package com.dsf.lembda.test;

import com.dsf.lembda.entity.Employee;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: Dgg
 * @Date: 2021/3/16 20:58
 */
public class StreamFilterPredicate {
	public static void main(String[] args){
		Employee e1 = new Employee(1,23,"M","Rick","Beethovan");
		Employee e2 = new Employee(2,13,"F","Martina","Hengis");
		Employee e3 = new Employee(3,43,"M","Ricky","Martin");
		Employee e4 = new Employee(4,26,"M","Jon","Lowman");
		Employee e5 = new Employee(5,19,"F","Cristine","Maria");
		Employee e6 = new Employee(6,15,"M","David","Feezor");
		Employee e7 = new Employee(7,68,"F","Melissa","Roy");
		Employee e8 = new Employee(8,79,"M","Alex","Gussin");
		Employee e9 = new Employee(9,15,"F","Neetu","Singh");
		Employee e10 = new Employee(10,45,"M","Naveen","Jain");


		List<Employee> employees = Arrays.asList(e1, e2, e3, e4, e5, e6, e7, e8, e9, e10);
		/**
		 * 谓词逻辑
		 */
		/*
		List<Employee> filtered = employees.stream()
				.filter(e -> e.getAge() > 70 && e.getGender().equals("M"))
				.collect(Collectors.toList());*/
		//使用and
		/*List<Employee> filtered = employees.stream()
				.filter(Employee.ageGreaterThan70.and(Employee.genderM))
				.collect(Collectors.toList());*/
		//使用 or
		/*List<Employee> filtered = employees.stream()
				.filter(Employee.ageGreaterThan70.or(Employee.genderM))
				.collect(Collectors.toList());*/
		// 取反
		List<Employee> filtered = employees.stream()
				.filter(Employee.ageGreaterThan70.or(Employee.genderM).negate())
				.collect(Collectors.toList());
		System.out.println(filtered);

	}

}
